// import store from './index'

//http://localhost:9191/savedb/addalarm?alarm=1$2024-12-05 12:12:13$站点1$1#温度$越限报警
//http://localhost:9191/savedb/addinfo?info=2024-12-16 12:12:13$站点1$越限报警

// 报警信息管理
export default {
    state: {
        //报警对象结构  { alarmtype: 1,  dt: '2024-09-21 00:00:00', station: "1#机组", descr: "1#机组开启", alarmtypedescr: "报警类型" }
        alarmdat: [],
        //{ dt: '2024-09-21 00:00:00',  descr: "组态提示信息"  }
        infodat: [],

        txtInfo: "信息栏",
        alarmDescr: "报警栏",
        alarmType: 0,
    },
    mutations: {
        // addAlarm(  state , alarm  ){
        //     state.alarmdat.unshift( alarm )
        // }

        addAlarm( state,  { alarmtype,  dt, station, descr, alarmtypedescr, projectname}  ){
            var v = { alarmtype:alarmtype,  dt:dt, station:station, descr:descr, alarmtypedescr:alarmtypedescr, projectname: projectname }  
            state.alarmdat.unshift( v )

            //如果超过300条，删除尾部的信息
        },

        addAlarmStr( state, alarmmsg ){
            //console.log( "alarm msg:" ,   alarmmsg )
            let list = alarmmsg.split("$")
            if( list.length < 5  )  return

            var v = { alarmtype:  Number(list[0]),  dt:list[1], station:list[2], descr:list[3], alarmtypedescr:list[4], projectname:list[5] }
            state.alarmdat.unshift( v )
            state.alarmType = v.alarmtype
            state.alarmDescr = v.descr
            // console.log( "alarm v:" , v )
        },

        addAlarmArray( state,  alarmarray  ){
            Array.prototype.push.apply( state.alarmdat, alarmarray );
            // console.log( "add alarm array", alarmarray )
        },

        addInfo( state,  {  dt, site,  descr, projectname}  ){
            var v = {  dt:dt, descr:descr, projectname:projectname }
            // console.log( "add info", v )
            state.infodat.unshift( v )

        },

        addInfoStr( state,  infostr  ){
            let list = infostr.split("$")
            if( list.length < 3  )  return
            var v = {  dt:list[0],  site:list[1], descr:list[2], projectname:list[3] }
            // console.log( "add info", v ) 
            state.infodat.unshift( v )
            state.txtInfo = v.descr  //改变状态栏中信息区域的信息
        },
          
    },
}
